
using UnityEngine;
using System.Collections;

public class Bola : MonoBehaviour {

    int id = 0;
	public int pontos = 0;
	
		

	void Start () 
    {
        this.gameObject.AddComponent("MeshRenderer");
        this.gameObject.AddComponent("MeshFilter");
        this.gameObject.AddComponent("BoxCollider");

        this.gameObject.GetComponent<BoxCollider>().size = new Vector3(0.95f, 0.3f, 0.5f);
        
        transform.localPosition = new Vector3(0f, -4f, 0f);
       

        Mesh mesh = Quad.Create(0.5f, 0.2f);

        this.gameObject.GetComponent<MeshFilter>().mesh = mesh;
        this.gameObject.GetComponent<MeshRenderer>().material = AtlasManager.globalMaterial;

        this.gameObject.GetComponent<MeshFilter>().mesh.uv = new Vector2[]
		{
			new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMax),
			new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMax),
			new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMin),
			new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMin)
		};
	}

	
	
	void Update () 
    {
     	

        this.gameObject.GetComponent<MeshFilter>().mesh.uv = new Vector2[]
		{
			new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMax),
			new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMax),
			new Vector2(AtlasManager.rects[id].xMax, AtlasManager.rects[id].yMin),
			new Vector2(AtlasManager.rects[id].xMin, AtlasManager.rects[id].yMin)
		};

        }

        void OnMouseDown()
        {
            pontos ++;
            Debug.Log("pontos:" + pontos);
        }   
	
	}

	


